package com.bootdo.coach.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.coach.dao.TabCoachMapper;
import com.bootdo.coach.dao.ext.ExtTabCoachMapper;
import com.bootdo.coach.domain.TabCoach;
import com.bootdo.coach.service.TabCoachService;
import com.bootdo.coach.vo.TabCoachVo;


@Service
public class TabCoachServiceImpl implements TabCoachService {
    @Autowired
    private TabCoachMapper mapper;
    
    @Autowired
    private ExtTabCoachMapper extMapper;

	@Override
	public int deleteByPrimaryKey(Long coachId) {
		return mapper.deleteByPrimaryKey(coachId);
	}

	@Override
	public int insert(TabCoach record) {
		return mapper.insert(record);
	}

	@Override
	public int insertSelective(TabCoach record) {
		return mapper.insertSelective(record);
	}

	@Override
	public TabCoach selectByPrimaryKey(Long coachId) {
		return mapper.selectByPrimaryKey(coachId);
	}

	@Override
	public int updateByPrimaryKeySelective(TabCoach record) {
		return mapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(TabCoach record) {
		return mapper.updateByPrimaryKey(record);
	}

    @Override
    public TabCoach findCoachByAccount(String account) {
    	List<TabCoach> list = extMapper.findCoachListByAccount(account);
    	if (list == null || list.isEmpty()) {
    		return null;
		}
    	return list.get(0);
    }

	@Override
	public List<Map<String, Object>> findCoachList(Map<String, Object> paramMap) {
		return extMapper.findCoachList(paramMap);
	}
	
	@Override
	public void updateAgentId(Long agentId, Long higherAgentId) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("higherAgentId", higherAgentId);
		paramMap.put("agentId", agentId);
		extMapper.updateAgentId(paramMap);
	}
	
	@Override
	public boolean exitCoachByAgentId(Long agentId) {
		List<TabCoach> list = extMapper.findCoachListByAgentId(agentId);
    	if (list == null || list.isEmpty()) {
    		return false;
		}
    	return true;
	}
	
	@Override
	public int count(Map<String, Object> query) {
		return extMapper.count(query);
	}

	@Override
	public List<TabCoachVo> list(Map<String, Object> query) {
		return extMapper.list(query);
	}

	@Override
	public boolean exitCoachName(Map<String, Object> params) {
		boolean exit;
        exit = extMapper.list(params).size() > 0;
        return exit;
	}
	
	@Override
	public List<TabCoach> findCoachList(Long agentId) {
		return extMapper.getCoachList(agentId);
	}
	
	@Override
	public Set<Long> findCoachIdList(Set<Long> agentIdList) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("agentIdList", agentIdList);
		return extMapper.findCoachIdList(paramMap);
	}
}
